//
//  XJSearchViewController.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/9.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJSearchViewController.h"

@interface XJSearchViewController ()

@property (nonatomic, strong) UISearchBar * searchBar;

@property (nonatomic, strong) UIButton * cancelBtn;

@end

@implementation XJSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.searchBar.placeholder = @"搜索的说明";
    self.searchBar.backgroundColor = WHITE_COLOR;
    self.searchBar.tintColor = BLACK_COLOR;
    [self.searchBar setBackgroundImage:[[UIImage alloc]init]];
    [self.searchBar setImage:[UIImage imageNamed:@"nav_search"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    UITextField * searchField=[self.searchBar valueForKey:@"_searchField"];
    searchField.backgroundColor = XJCOLOR_RGB(246, 247, 249);
    searchField.layer.masksToBounds = YES;
    searchField.layer.cornerRadius = 18.0;
    UILabel * searchPlaceholderLabel = [searchField valueForKey:@"_placeholderLabel"];
    searchPlaceholderLabel.font = XJFONTSET_R(13);
    [searchField setValue:XJCOLOR_RGB(185, 194, 197) forKeyPath:@"_placeholderLabel.textColor"];

    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = XJFONTSET_R(14);
    [self.cancelBtn setTitleColor:XJCOLOR_RGB(17,17,17) forState:UIControlStateNormal];
    CGSize cancelBtnSize = [UIButton getSizeFromButtonTitle:@"取消" Font:XJFONTSET_R(14)];
    [self.cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.cancelBtn.sd_layout
    .rightSpaceToView(self.view, ADAPTWidth(17))
    .centerYEqualToView(self.searchBar)
    .widthIs(cancelBtnSize.width)
    .heightIs(cancelBtnSize.height);
}

- (UISearchBar *)searchBar{
    
    if (!_searchBar) {
        UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(ADAPTWidth(15),UI_IS_IPHONE5?ADAPTHeight(29):ADAPTHeight(9), ADAPTWidth(300), ADAPTHeight(60))];
        self.searchBar = searchBar;
        [self.view addSubview:searchBar];
    }
    return _searchBar;
}

- (UIButton *)cancelBtn{
    
    if (!_cancelBtn) {
        UIButton * cancelBtn = [UIButton new];
        self.cancelBtn = cancelBtn;
        [self.view addSubview:cancelBtn];
    }
    return _cancelBtn;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
}

- (void)cancelBtnClick{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
  //  self.tabBarController.tabBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
